﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;

namespace DAL
{
    public class CommentService
    {
        public static List<CommentF> SelectAllByPID(int pid)
        {
            string sql = "select a.Commentid,a.Uid,a.Foodid,a.Comments,a.Star,a.CommentTime," +
                "b.NickName NickName from Comment a " +
                "join UserInfo b on a.Uid=b.Uid where foodid=" + pid;
            SqlDataReader dr = DBHelperSQL.GetDataReader(sql);
            List<CommentF> list = new List<CommentF>();
            while (dr.Read())
            {
                CommentF c = new CommentF();

                c.Commentid = dr.GetInt32(0);
                c.Uid = dr.GetInt32(1);
                c.Foodid = dr.GetInt32(2);
                c.Comments = dr.GetString(3);
                c.Star = dr.GetInt32(4);
                c.CommentTime = dr.GetDateTime(5);
                c.NickName = dr.GetString(6);

                list.Add(c);
            }
            dr.Close();
            return list;
        }
        public static bool Add(CommentF c)//增
        {
            string sql = string.Format("insert Comment values({0},{1},'{2}',5,GETDATE())",
                c.Uid, c.Foodid, c.Comments);
            return DBHelperSQL.ExecuteNonQuery(sql);
        }
    }
}
